<template>
  <view>
    <uni-nav-bar :fixed="true" background-color="#b6edaa" color='#fff' status-bar left-icon="left" title="任务详情"
      :border="false" @clickLeft='back' />
    <view class="taskInfo">
      <view class="image">
        <image src="/static/taskImg.jpg" mode=""></image>
      </view>
      <view class="mainTaskDetail">
        <view class="textDetail">
          <view class="taskTitle">
            <view class="image">
              <image src="/static/task-logo.png"></image>
            </view>
            <text>{{item.branchTaskName}}</text>
          </view>
          <view class="taskDescribe">
            {{item.description}}
          </view>
          <view class="taskFooter">
            <view class="taskIntegral">
              积分：{{item.integral}}
            </view>
            <view class="taskComplete">
              已完成：{{item.branchCount}}
            </view>
          </view>
          <view class="main-status ok" v-if="item.completed === '已完成'">
            {{item.completed}}
          </view>
        </view>
      </view>
    </view>

    <view class="footer" v-if='item.completed != "已完成" '>
      <view class="btn-box">
        <view class="btn" @click="clockOn()">
          打卡
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import {
    mapState
  } from 'vuex'
  export default {
    data() {
      return {
        taskId: 0,
        branchId: 0,
        item: {},
        status: ['', '已完成', '进行中']
      };
    },
    onLoad(options) {
      this.taskId = options.taskId
      this.branchId = options.branchId
      this.getTaskInfo()
    },
    methods: {
      back() {
        uni.navigateBack()
      },
      async getTaskInfo() {
        let that = this
        const obj = {
          studentId: that.userInfo.studentId,
          mainTaskId: that.taskId,
          branchTaskId: that.branchId
        }
        const data = await uni.$http.post('/users/tasks/branchtask/detail', obj)
        console.log(data.data.data);
        this.item = data.data.data
      },
      clockOn() {
        const type = 2
        if (this.item.punchType === '定位打卡') {
          uni.navigateTo({
            url: `/subpkg/mapClock/mapClock?taskId=${this.taskId}&branchId=${this.branchId}&type=${type}`
          })
        } else if (this.item.punchType === '视频打卡') {
          uni.navigateTo({
            url: `/subpkg/videoClock/videoClock?taskId=${this.taskId}&branchId=${this.branchId}&type=${type}`
          })
        }
      }
    },
    computed: {
      ...mapState('my_user', ['userInfo'])
    }
  }
</script>

<style lang="scss">
  .header {
    position: relative;
    width: 100%;
    height: 140rpx;
    text-align: center;
    font-size: 36rpx;
    font-weight: 700;
    line-height: 170rpx;
    background-color: #b6edaa;
    color: #fff;

    .back {
      position: absolute;
      top: 4rpx;
      left: 23rpx;
      height: 50rpx;
    }
  }

  .taskInfo {
    width: 100%;

    .image {
      width: 100%;
      height: 350rpx;

      image {
        width: 100%;
        height: 100%;
      }
    }

    .mainTaskDetail {
      height: 300rpx;
      background-color: #fff;

      .textDetail {
        position: relative;
        display: flex;
        flex-direction: column;
        margin-top: 20rpx;
        padding: 0 20rpx;
        padding-bottom: 10rpx;
        background-color: #fff;

        .taskTitle {
          display: flex;
          align-items: center;
          height: 80rpx;
          font-size: 36rpx;
          line-height: 80rpx;
          color: #333;

          .image {
            width: 40rpx;
            height: 40rpx;

            image {
              display: block;
              width: 100%;
              height: 100%;
            }
          }

          text {
            margin-left: 20rpx;
          }
        }

        .taskDescribe {
          padding: 10rpx 0;
          font-size: 32rpx;
          color: #555;
        }

        .taskFooter {
          display: flex;
          justify-content: space-between;
          margin-top: 10rpx;
          padding: 10rpx 0;
          color: #666;

          .taskIntegral {
            font-size: 30rpx;
            color: #ae9986;
          }

          .taskComplete {

            color: #888;
          }
        }

        .main-status {
          position: absolute;
          top: 30rpx;
          right: 30rpx;
          margin-bottom: 100rpx;
          padding: 6rpx 12rpx;
          color: #fff;
          font-size: 30rpx;
        }
      }
    }
  }

  .footer {
    position: relative;
    width: 90%;
    height: 780rpx;
    margin: 0 auto;
    margin-top: 50rpx;
    background-color: #fff;

    .btn-box {
      position: absolute;
      top: 220rpx;
      left: 180rpx;
      width: 310rpx;
      height: 310rpx;
      border: 8rpx solid #c4eebe;
      border-radius: 50%;

      .btn {
        width: 280rpx;
        height: 280rpx;
        margin: 15rpx auto;
        border-radius: 50%;
        background-color: #b6edaa;
        text-align: center;
        line-height: 280rpx;
        font-size: 50rpx;
        color: #fff;
      }
    }
  }
</style>